package com.conversationboard.model;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

public enum Colour {

	NotSet("Not Set", ""), Black("Black", "#000000"), Red("Red", "#FF0000"), Green("Green", "#00FF00"), Blue("Blue", "#0000FF"), Salmon("Salmon", "#FFA07A"), Pink("Pink", "#FDC0CB"), Wheat("Wheat", "#F5DEB3"), LimeGreen("Lime Green", "#32CD32"), Olive("Olive", "#666600"), Orange("Orange", "#FFA500"), Aquamarine("Aquamarine", "#7FFFD4"), SteelBlue("Steel Blue", "#4682B4"), Grey("Grey", "#808080"), Ivory(
			"Ivory", "#FFFFF0"), Indigo("Indigo", "#4B0082"), Navy("Navy", "#000080"), Brown("Brown", "#A52A2A"), EaglesGreen("Eagles Green", "#005500"), Maroon("Maroon", "#990099");

	private String displayName;
	private String htmlCode;
	private static Map<String, String> darkerVersions = new HashMap<String, String>();

	static {

		/* Create lower brightness versions of colours and store them */

		for (Colour colour : Colour.values()) {
			String darkerVersion = colour.createLowerBrightnessVersion();
			darkerVersions.put(colour.getHtmlCode(), darkerVersion.toUpperCase());
		}

	}


	Colour(String displayName, String htmlCode) {
		this.displayName = displayName;
		this.htmlCode = htmlCode;
	}


	public String getDisplayName() {
		return displayName;
	}


	public String getHtmlCode() {
		return htmlCode;
	}


	private String createLowerBrightnessVersion() {

		if (this == Colour.NotSet) {
			return "";
		}

		Color colour = Color.decode("0x" + this.getHtmlCode().substring(1));

		Color darkerColour = colour.darker();

		String rgb = Integer.toHexString(darkerColour.getRGB());
		rgb = rgb.substring(2, rgb.length());

		return "#" + rgb;
	}


	public String getLowerBrightnessVersion() {

		if (this == Colour.NotSet) {
			return "";
		} else {
			return darkerVersions.get(this.getDisplayName());
		}

	}


	public static String getDarkerVersion(String htmlCode) {
		return darkerVersions.get(htmlCode);
	}

}
